import React, { Component } from 'react';
// 导入 商品切片对应的方法
import { editname, addprice } from '../../store-rtk/reducers/goodsReducer';
import { connect } from 'react-redux'

class Class2 extends Component {
    render() {

        // console.log(this);
        const { editFn, priceFn, goods } = this.props
        return (
            <div>
                <p>
                    <button onClick={() => {
                        editFn()
                    }}>修改名字</button>
                    <span>{goods.goodsname}---{goods.price}</span>
                    <button onClick={() => {
                        priceFn()
                    }}>修改价格</button>
                </p>
            </div>
        );
    }
}

// 将仓库中的state 数据映射到组件自身的props 属性上
function mapstatetoprops(state) {
    return state
}

function mapdispatchtoprops(dispatch) {
    return {
        editFn() {
            dispatch(editname('布洛芬胶囊'))
        },
        priceFn() {
            dispatch(addprice(20))
        }

    }
}


export default connect(mapstatetoprops, mapdispatchtoprops)(Class2);
